import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Random;
import java.util.Collections.*;

public class Deck 
{
	private Card[] cards;
	private List<Card> stack;
	private int start;
	
	Deck()
	{
		cards = new Card[52];
		String[] colors = {"SPADE", "HEART", "DIAMOND", "CLUB"};
		stack = new ArrayList<Card>();
		start = 0;
	
		Random randomizer = new Random();

		List<Card> temp = new ArrayList<Card>();

		for(int i = 1; i < 14; i++)
		{
			for(String j : colors)
				temp.add(new Card(i, j));
		}
		
		Collections.shuffle(temp);
		for(int i = 0; i < temp.size(); i++)
		cards[i] = temp.get(i);
	}
	
	public Card[] getCards(int count)
	{
		Card[] temp = new Card[count];
		
		if(52 - start - count >= 0)
		{
			for(int i = 0; i < count; i++)
			{
				temp[i] = cards[start];
				start++;
			}
			return temp;
		}
		
		if(start == 52)
		{
			Collections.shuffle(stack);
			for(int i = 0; i < count; i++)
			{
				temp[i] = stack.get(i);
				stack.remove(i);
			}
			return temp;
		}
		
		while(start < 52)
		{
			stack.add(cards[start]);
			start++;
		}
		
		Collections.shuffle(stack);
		for(int i = 0; i < count; i++)
		{
			temp[i] = stack.get(i);
			stack.remove(i);
		}
		
		return temp;
	}
	
	public void removeFromHand(Card i)
	{
		stack.add(i);
	}
}
